package tech.zjp.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tech.zjp.ssm.entity.Role;
import tech.zjp.ssm.mapper.RoleMapper;
import tech.zjp.ssm.mapper.UserMapper;
import tech.zjp.ssm.service.RoleService;

/**
 *
 * @Description: 
 * @Author: 周军鹏
 * @Date: 2020年3月4日 下午2:35:41
 */
@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleMapper roleMapper;
	@Autowired
	private UserMapper userMapper;

	@Override
	public List<Role> getRoleList() {
		return roleMapper.getRoleList();
	}

	@Override
	public boolean add(Role role)  {
		// TODO Auto-generated method stub
		boolean flag = false;
		if(roleMapper.add(role) > 0)
			flag = true;
		return flag;
	}

	@Override
	public boolean deleteRoleById(Integer delId)  {
		boolean flag = false;
		if(userMapper.getUserCount(null, delId) == 0){
			if(roleMapper.deleteRoleById(delId) > 0)
				flag = true;
		}
		return flag;
	}

	@Override
	public boolean modify(Role role)  {
		return roleMapper.modify(role) > 0?true:false;
	}

	@Override
	public Role getRoleById(Integer id)  {
		return roleMapper.getRoleById(id);
	}

	@Override
	public int roleCodeIsExist(String roleCode)  {
		return roleMapper.roleCodeIsExist(roleCode);
	}

}
